package com.qiangqiang.task.server.controller;

import com.qiangqiang.task.server.entity.Post;
import com.qiangqiang.task.server.service.PostService;
import com.qiangqiang.task.server.util.ResultVOUtil;
import com.qiangqiang.task.server.vo.ResultVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: task
 * @description:
 * @author: Sky.lin
 * @create: 2018-12-20 20:50
 **/
@RestController
@RequestMapping(value = "/post")
public class PostController {


    @Autowired
    PostService postService;

    @PostMapping("/addPost")
    public ResultVO addPost(Post post) {
        return ResultVOUtil.success(postService.addPost(post));
    }

    @GetMapping("/showAllPost")
    public ResultVO showAllPost(@Param("page") int page, @Param("pageSize") int pageSize) {
        return ResultVOUtil.success(postService.findAllPost(page, pageSize));
    }

    @GetMapping("/showPostByUserId")
    public ResultVO showPostByUserId(@Param("userId") long userId) {
        return ResultVOUtil.success(postService.findPostByUserId(userId));
    }
}
